var userInfomation,userInfoObj;
var userName = '';
var userSex = '';
var userBirth = '';
var userPhone = '';
var userEmail = '';
var userPhotoUrl = '';
mui.init();

mui.plusReady(function() {
	userInfomation = localStorage.getItem("userInfo");
	userInfoObj = JSON.parse(userInfomation);
	console.log(userInfomation);
	userPhotoUrl = userInfoObj.photo;
	userName = userInfoObj.userName;
	userSex = userInfoObj.sex;
	userBirth = userInfoObj.addDate;
	userPhone = userInfoObj.mobilePhone;
	userEmail = userInfoObj.email;
	if(userPhotoUrl !== null && userPhotoUrl !== '') {
		document.getElementById('avatar').src = userPhotoUrl || '../../images/firemen.svg';
	}
	if(userName !== null && userName !== '') {
		document.getElementById('userName').innerText = userName;
		document.getElementById('avtarName').innerText = userName;
	}
	// if(userSex !== null && userSex !== '') {
	// 	if(userSex == 1){
	// 		document.getElementById('userSex').innerText = '男';
	// 	}else {
	// 		document.getElementById('userSex').innerText = '女';
	// 	}
		
	// }
	if(userBirth !== null && userBirth !== '') {
		document.getElementById('userBirth').innerText = userBirth || "";
	}
	if(userPhone !== null && userPhone !== '') {
		document.getElementById('userPhone').innerText = userPhone || "";
	}
	if(userEmail !== null && userEmail !== '') {
		document.getElementById('userEmail').innerText = userEmail || "";
	}
	
	document.getElementById('logOut').addEventListener('tap', function(){
		
		var btnArray = ['取消', '确定'];
		mui.confirm('确定退出应用吗？','提示', btnArray,function(e){
			if (e.index == 1) {
				localStorage.removeItem("userInfo");
// 				var all = plus.webview.all;
// 				for(var i = 0;i < all.length; i++) {
// 					all[i].close();
// 				}
				mui.openWindow({
					id: 'login',
					url: '../../html/login/login.html',
					createNew: true
				})
			}
		}, false)
	})
});

//波浪线
var canvas = document.getElementById('canvas');
var ctx = canvas.getContext('2d');

requestAnimFrame = (function() {
	return function(callback) {
		setTimeout(callback, 18);
	};
})();

//初始角度为0  
var step = 90;
//定义三条不同波浪的颜色  
var lines = ["112,153,249, 0.7)",
	"rgba(112,153,249, 0.5)",
	"rgba(112,153,249, 0.7)",
	"rgba(112,153,249, 0.5)"
];

function loop() {
	ctx.clearRect(0, 0, canvas.width, canvas.height);
	step++;
	//画3个不同颜色的矩形  
	for(var j = lines.length - 1; j >= 0; j--) {
		ctx.fillStyle = lines[j];
		//每个矩形的角度都不同，每个之间相差45度  
		var angle = (step + j * 90) * Math.PI / 180;
		var deltaHeight = Math.sin(angle) * 50 + 30;
		var deltaHeightRight = Math.cos(angle) * 50 + 30;
		ctx.beginPath();
		ctx.moveTo(0, canvas.height / 2 + deltaHeight);
		ctx.bezierCurveTo(canvas.width / 2, canvas.height / 2 + deltaHeight, canvas.width / 2, canvas.height / 2 + deltaHeightRight, canvas.width, canvas.height / 2 + deltaHeightRight);
		ctx.lineTo(canvas.width, canvas.height);
		ctx.lineTo(0, canvas.height);
		ctx.lineTo(0, canvas.height / 2 + deltaHeight);
		ctx.closePath();
		ctx.fill();
	}
	requestAnimFrame(loop);
}
loop();